clear all;
close all;
clc;

Fd = 40e3;
Td = 1/Fd;
Tmod = 0.05;
t = 0:Td:Tmod;
L = length(t);

S = cos(2*pi* (500 + 100 * rand(1,1)) * t);
PZW = parzenwin(L);
SW = S .* PZW';
figure
plot(t,S,t,SW);

%N = 2^nextpow2(L);
%F = fft(S,N)/L;
%f = Fd/2*linspace(0,1,N/2+1);

%figure
%plot(f,2*abs(F(1:N/2+1)))
%sprintf('maxf=%f\n',max(F))
%[C,I] = max(2*abs(F(1:N/2+1)));
%sprintf('f=%f\n',f(I))

Sf = fft(S);
Sfw = fft(SW);
T = Tmod + Td;
f = 0:1/T:(1/Td - 1/T);

figure
plot(f, abs(Sf),f, abs(Sfw))
xlabel('f, Hz');
ylabel('|Df|');
xlim([0,1000]);

[C,I] = max(abs(Sf));
sprintf('f = %f',f(I))
